<template>
  <view class="custom-input">
    <u-input
      v-model="inputValue"
      :placeholder="placeholder"
      :border="border"
      :clearable="clearable"
    />
	 <!-- 显示已上传的图片 -->
	    <image v-if="inputValue" :src="inputValue" class="uploaded-image-preview" />
	    
    <view class="upload-button" @tap="openImagePicker">+</view>
  </view>
</template>

<script>
export default {
  props: {
    placeholder: String, 
    border: String,
    clearable: Boolean,
  },
  data() {
    return {
      inputValue: '',
    };
  },
  methods: {
    openImagePicker() {
      // 打开图片选择器
      uni.chooseImage({
        count: 1, // 最多选择一张图片
        success: (res) => {
          const tempFilePaths = res.tempFilePaths;
          if (tempFilePaths.length > 0) {
            // 上传图片逻辑
            const imageUrl = tempFilePaths[0];
            // 这里可以使用 uni.uploadFile 或其他文件上传方法
            // 上传成功后，将图片的 URL 赋值给 inputValue
            this.inputValue = imageUrl;
          }
        },
      });
    },
  },
};
</script>

<style scoped>
.custom-input {
  display: flex;
  align-items: center;
}

.upload-button {
  width: 40px;
  height: 40px;
  background-color: #007AFF;
  color: #fff;
  text-align: center;
  line-height: 40px;
  border-radius: 50%;
  margin-left: 10px;
  cursor: pointer;
}
</style>
